<template>
	<view class="container pt_8">
		<view class="bc_fff">
			<view class="ptb_8 plr_16 fx jcb" v-for="item,index in dataList" :key="index">
				<template v-if="type=='redpacketShare'">
					<view class="fx aic fx_1 flow_h">
						<CustomImage width="80rpx" height="80rpx" radius="40rpx"
							:src="item.customerAvatar">
						</CustomImage>
						<view class="ml_8 fx_1 flow_h">
							<view class="fe">
								{{item.customerName||''}}
							</view>
							<view class="fc_999 mt_4">
								{{item.date}}
							</view>
						</view>
					</view>
					<view class="fc_333 pl_8">
						+{{item.amount}}金豆
					</view>
				</template>
				<template v-else>
					<view class="fx_1 flow_h">
						<view class="fe">
							{{type=='redpacketCustom'?`抢红包获得金豆`:type=='pointTransform'?(item.showType=='积分兑换金豆'||item.showType=='每月会员收益转化积分')?tranformStr(item):(item.showType||''):(item.showType||'')}}
						</view>
						<view class="fc_999 mt_4">
							{{item.updateTime||item.receiveTime||item.date||''}}
						</view>
					</view>
					<view class="fc_333" v-if="type=='redpacketCustom'">
						{{item.amount>0?'+':''}}{{item.amount||0}}金豆
					</view>
					<view class="fc_primary pl_8" v-else-if="type=='pointTransform'">
						{{item.legumesAmount>0?'+':''}}{{item.legumesAmount||0}}金豆
					</view>
					<view class="fc_333 pl_8" v-else>
						{{item.amount>0?'+':''}}{{item.amount||0}}{{typeName}}
					</view>
				</template>
			</view>
		</view>
		<view class="pt_16" v-if="dataList.length">
			<u-loadmore :status="loadingStatus" />
		</view>
		<view class="pt_36" v-if="!dataList.length&&!loading">
			<Empty type="record" />
		</view>
	</view>
</template>

<script>
	import CustomImage from '@/components/Image'
	import Empty from '@/components/Empty'
	import dataMixin from '@/mixins/data.js'
	import api from '@/service/config/api'
	export default {
		mixins: [dataMixin],
		components: {
			CustomImage,
			Empty
		},
		data() {
			return {
				type: '',
				typeName: '',
				dataList: [],
				listUrl: '',
				params: {
					type: 1
				},
				httpMethod: 'post'
			}
		},
		computed: {
			tranformStr() {
				return item => {
					if(item.showType=='每月会员收益转化积分') {
						return `每月会员收益转化${-item.amount}积分`
					}
					switch(item.operateType) {
						case 1: 
						return `转发商品转换${-item.amount}积分`
						case 2: 
						return `浏览商品转换${-item.amount}积分`
						case 3: 
						return `邀请新用户注册转换${-item.amount}积分`
						case 4: 
						return `评价商品转换${-item.amount}积分`
						case 5: 
						return `推荐用户购买转换${-item.amount}积分`
						default:
						return `转换${-item.amount}积分`
					}
				}
			},
		},
		onLoad(options) {
			this.type = options.type || ''
			if (this.type) {
				if (this.type == 'redpacketCustom' || this.type == 'redpacketShare') {
					this.httpMethod = 'get'
				}
				this.getTypeData()
				this.getData(true)
			} else {
				this.$utils.showToast('未查到记录类型', 1500, 1)
			}
		},
		methods: {
			getData(refresh = false) {
				return new Promise(resolve => {
					this.isSearching = true
					if (refresh) {
						this.current = 1
						this.total = 1
						this.$utils.loading()
					} else {
						this.loading = true
					}
					if (this.listUrl) {
						api[this.httpMethod](this.listUrl, {
							current: this.current,
							size: this.size,
							...this.params ? this.params : {}
						}).then(res => {
							this.dataList = refresh ? (res.data.records || []) : [...this.dataList, ...(res
								.data
								.records || [])];
							if (res.data.total <= this.dataList.length) {
								this.end = true
							}
							this.getDataNext && this.getDataNext()
						}).finally(() => {
							this.loading = false
							this.initLoading = false
							resolve()
						})
					}
				})
			},
			getTypeData() {
				switch (this.type) {
					case 'point':
						uni.setNavigationBarTitle({
							title: '积分明细'
						})
						this.listUrl = '/user/api/myScoring/page'
						this.typeName = '积分'
						this.$set(this.params, 'type', 2)
						break
					case 'pointTransform':
						uni.setNavigationBarTitle({
							title: '转化明细'
						})
						this.listUrl = '/user/api/myScoring/page'
						this.typeName = '金豆'
						this.$set(this.params, 'type', 1)
						break
					case 'coin':
						uni.setNavigationBarTitle({
							title: '金豆明细'
						})
						this.listUrl = '/user/api/myLegumes/myPage'
						this.typeName = '金豆'
						this.$delete(this.params, 'type')
						break
					case 'redpacketCustom':
						uni.setNavigationBarTitle({
							title: '获得红包记录'
						})
						this.listUrl = '/marketing/web/api/backstage/red_packet/record/my/page'
						this.typeName = ''
						this.$delete(this.params, 'type')
						this.$set(this.params, 'receiveType', 1)
						break
					case 'redpacketShare':
						uni.setNavigationBarTitle({
							title: '共享红包记录'
						})
						this.listUrl = '/marketing/web/api/backstage/red_packet/record/my/page'
						this.typeName = ''
						this.$delete(this.params, 'type')
						this.$set(this.params, 'receiveType', 2)
						break
					default:
						break
				}
			}
		},
	}
</script>

<style lang="scss">
	.container {}
</style>